import { defineStore } from 'pinia'
import { requestAllUserInfo, requestSearchUserInfoByUidOrUserId, requestDeleteUserById } from './manage-user.api'

export default defineStore('manageUser', {
    state: () => {
        return {
        }
    },
    getters: {
    },
    actions: {
        // 获取全部用户信息
        getAllUserInfo() {
            return new Promise((resolve, reject) => {
                requestAllUserInfo().then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 查询用户信息
        getSearchUserInfoByUidOrUserId(data: object) {
            return new Promise((resolve, reject) => {
                requestSearchUserInfoByUidOrUserId(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 根据uid删除用户信息
        getDeleteUserById(data: object) {
            return new Promise((resolve, reject) => {
                requestDeleteUserById(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },
    }
})
